package com.lzq.mq.broker.core;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ConsumeQueue的MMap映射的管理器
 */
public class ConsumeQueueMMapFileModelManager {

    /**
     * topic到消费队列MMap的映射
     */
    private final Map<String, List<ConsumeQueueMMapFileModel>> consumeQueueMMapFileModelMap = new HashMap<>();

    /**
     * 添加topic和ConsumeQueueMMapFileModel列表
     * @param topic  topic
     * @param consumeQueueMMapFileModelList ConsumeQueueMMapFileModel列表
     */
    public void put(String topic, List<ConsumeQueueMMapFileModel> consumeQueueMMapFileModelList) {
        consumeQueueMMapFileModelMap.put(topic, consumeQueueMMapFileModelList);
    }

    /**
     * 获取指定topic的ConsumeQueueMMapFileModel列表
     * @param topic  topic
     * @return ConsumeQueueMMapFileModel列表
     */
    public List<ConsumeQueueMMapFileModel> getTopicConsumeQueueMMapFileModelList(String topic) {
        return consumeQueueMMapFileModelMap.get(topic);
    }

    /**
     * 获取指定topic和queueId的ConsumeQueueMMapFileModel
     * @param topic  topic
     * @param queueId queueId
     * @return ConsumeQueueMMapFileModel
     */
    public ConsumeQueueMMapFileModel getConsumeQueueMMapFileModel(String topic, int queueId) {
        return consumeQueueMMapFileModelMap.get(topic).get(queueId);
    }
}
